home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / lfs / lfsSeg.h < prev    next >
C/C++ Source or Header  |  1991-08-08  |  12KB  |  315 lines

  1. /*
  2.  * lfsSeg.h --
  3.  *
  4.  *    Declarations of segment writing/cleaning and checkpoint interface
  5.  *    for LFS.  Any module that wishes to write objects to the log
  6.  *    must register itself with the lfsSeg module and support this
  7.  *    interface.
  8.  *    
  9.  *
  10.  * Copyright 1989 Regents of the University of California
  11.  * Permission to use, copy, modify, and distribute this
  12.  * software and its documentation for any purpose and without
  13.  * fee is hereby granted, provided that the above copyright
  14.  * notice appear in all copies.  The University of California
  15.  * makes no representations about the suitability of this
  16.  * software for any purpose.  It is provided "as is" without
  17.  * express or implied warranty.
  18.  *
  19.  * $Header: /sprite/src/kernel/lfs/RCS/lfsSeg.h,v 1.9 91/08/08 17:49:41 mendel Exp $ SPRITE (Berkeley)
  20.  */
  21.  
  22. #ifndef _LFSSEG
  23. #define _LFSSEG
  24.  
  25. #include <lfsInt.h>
  26. #include <lfsSegLayout.h>
  27. #include <devBlockDevice.h>
  28.  
  29. /* 
  30.  * The interface to writing objects to the LFS log is operated using a 
  31.  * callback interface.  Any module may start a segment write by calling
  32.  * the LfsSegWriteStart(). The segment write code (in lfsSeg.c) then
  33.  * selects a clean segment on disk, initializes a LfsSeg structure for that
  34.  * segment, and calls the Layout() subroutine for each module.  The Layout()
  35.  * adds data blocks and/or summary bytes to the segment. Data blocks
  36.  * added to the LfsSeg may use a scatter/gather interface
  37.  * consisting of LfsSegElement structures will each SegElement pointing to
  38.  * zero or more blocks. Once the segment
  39.  * is full or all modules exhaust there need to write, the segment is pushed
  40.  * to disk and WriteDone() callback is done for each module writing data.
  41.  * 
  42.  */
  43.  
  44. /*
  45.  * Data blocks are added to LfsSeg structures in units of LfsSegElement's.
  46.  */
  47. typedef struct LfsSegElement {
  48.     Address       address;         /* The address of the start of the buffer. */
  49.     unsigned int lengthInBlocks;  /* Length of the buffer in units of file 
  50.                    * system blocks. */
  51.     ClientData   clientData;      /* ClientData usable by the callback 
  52.                    * functions. */
  53. } LfsSegElement;
  54.  
  55. /*
  56.  * LfsSegLogRange describes the position in the segmented log of a segment. 
  57.  */
  58. typedef struct LfsSegLogRange {
  59.     int        current;    /* Current segment being accessed */
  60.     int        prevSeg;    /* The segment that was written before the
  61.                  * current segment. */
  62.     int        nextSeg;    /* Next segment to be written after the
  63.                  * current segment. */
  64. } LfsSegLogRange;
  65.  
  66. /*
  67.  * The LfsSeg structure is used to describe a segment while objects are being
  68.  * added to the segment during writing and removed from the segment during
  69.  * cleaning.  A segment is divided into two regions: the data block region
  70.  * and the summary region.  The data block region is may contain zero to 
  71.  * the segment size (segmentSize in LfsSuperBlockHdr)-1 blocks. The blocks are
  72.  * pointed to by an array of LfsSegElement.  The summary region is allocated
  73.  * in bytes and may grow from one block to an entire segment.
  74.  */
  75.  
  76. typedef struct LfsSeg {
  77.     struct Lfs           *lfsPtr;    /* The LFS file system this segment belongs.
  78.                  * Static segment attributes such as number
  79.                  * blocks can be found in here. */
  80.     LfsSegElement *segElementPtr; /* The SegElements making up the data 
  81.                    * region of the segment. */
  82.     char       *memPtr;    /* Segment memory allocated for segment. */
  83.     LfsSegLogRange logRange;    /* Placement of segment in segmented log. */
  84.     int        numElements;      /* Number of LfsSegElement describing the 
  85.                    * segment. */
  86.     int        numBlocks;        /* Number of blocks in segment. */
  87.     int        startBlockOffset; /* Starting block offset of this segment. */
  88.     int        activeBytes;      /* Number of active bytes in segment. */
  89.     int        timeOfLastWrite;  /* Time of create of youngest block in seg. */
  90.     /*
  91.      * Some operations of segments require scanning thru the summary 
  92.      * and SegElements.  The following fields keep the start require
  93.      * from this scans. 
  94.      */
  95.     LfsSegSummary    *curSegSummaryPtr; /* Summary of current summary 
  96.                         * block. */
  97.     LfsSegSummaryHdr    *curSummaryHdrPtr; 
  98.                 /* Current module header being processed. */
  99.     int         curElement;    /* Current LfsSegElement. */
  100.     int         curBlockOffset;    /* The block offset into the segment of the
  101.                  * end of curElement. */
  102.     int         curDataBlockLimit;   /* Last block offset available in the 
  103.                    * segment. */
  104.     char     *curSummaryPtr;    /* Current offset into the summary region. */
  105.     char     *curSummaryLimitPtr; /* Current last byte of the summary block 
  106.                    * plus 1. */
  107.         /*
  108.          * It following fields are used during I/O.
  109.          */
  110.     Sync_Semaphore ioMutex;           /* Used to sync access to I/O structures
  111.                     */
  112.     Boolean      ioDone;           /* TRUE if I/O has finished. */
  113.     ReturnStatus ioReturnStatus;       /* ReturnStatus of I/O. */
  114.     Sync_Condition ioDoneWait;         /* Condition to wait for I/O finish. */
  115.     DevBlockDeviceRequest  bioreq[2]; /* Two request for double buffered I/O.*/
  116.     int        requestActive;          /* Number of IO request active. */
  117.     int        nextDiskAddress;      /* Next disk address to write. */
  118.  
  119. } LfsSeg;
  120.  
  121. /*
  122.  * The callback interface used by objects wishing to write data to the log is
  123.  * defined by the LfsSegIoInterface.   
  124.  * The exact function each of these layout procedures is 
  125.  * defined in LfsSeg.c
  126.  */
  127.  
  128. typedef struct LfsSegIoInterface {
  129.  
  130.     ReturnStatus (*attach) _ARGS_((struct Lfs *lfsPtr, int checkPointSize, 
  131.                 char *checkPointPtr));
  132.     /* File system attach routine. Calling sequence:
  133.      * attach(lfsPtr, checkPointSize, checkPointPtr)
  134.      *    Lfs *lfsPtr; -- File system to attach.
  135.      *    int  checkPointSize; Size of checkpoint data
  136.      *    char *checkPointPtr; Data from last checkpoint
  137.      * Attach is called when the file system is attached and is responsible
  138.      * for build any in memory data structures needed by the file system.
  139.      * The routine returns SUCCESS if things are going ok.
  140.      */
  141.  
  142.     Boolean (*layout) _ARGS_((LfsSeg *segPtr, int flags, 
  143.             ClientData *clientDataPtr));
  144.     /* Segment layout routine. Calling sequence:
  145.      * layout(segPtr, cleaning)
  146.      *     LfsSeg *segPtr; -- Segment to fill in.
  147.      *     int flags; -- Layout flags.
  148.      *     ClientData *clientData -- Clientdata for call.
  149.      * The module should place all the dirty blocks it can into the log.
  150.      * The routine returns TRUE if the module has more data that needs to
  151.      * be written to the log. 
  152.      */
  153.  
  154.     Boolean  (*clean) _ARGS_((LfsSeg *segPtr, int *sizePtr, 
  155.               int *numCacheBlocksPtr, ClientData *clientDataPtr));
  156.     /* Segment cleaning routine. Calling sequence:
  157.      * clean(segToCleanPtr, sizePtr)
  158.      *     LfsSeg *segToCleanPtr;  -- Segment to clean.
  159.      *     int    *sizePtr;           -- Size in blocks to data to clean.
  160.      * Copy the alive blocks from the segToClean into the cache.
  161.      */
  162.     Boolean (*checkpoint) _ARGS_((LfsSeg *segPtr, int flags, 
  163.             char *checkPointPtr, int *checkPointSizePtr, 
  164.             ClientData *clientDataPtr));
  165.  
  166.     /* Segment checkpoint routine. Calling sequence:
  167.      * checkpoint(segPtr, flags, checkPointPtr,  checkPointSizePtr)
  168.      *     LfsSeg *segPtr; -- Segment to fill in.
  169.      *     int    flags;    -- Defined in lfsInt.h
  170.      *     char *checkPointPtr; -- Checkpoint buffer.
  171.      *     int  *checkPointSizePtr -- Out: bytes added to checkpoint area.
  172.      * The routine returns TRUE if the module has more data that needs to
  173.      * be written to the log. 
  174.      */
  175.     void  (*writeDone)  _ARGS_((LfsSeg *segPtr, int flags, 
  176.                 ClientData *clientDataPtr));
  177.     /* Segment write finished callback. Calling seq:
  178.      * writeDone(segPtr, flags)
  179.      *     LfsSeg *segPtr; -- Segment finishing write.
  180.      *     int    flags;    -- Defined in lfsInt.h.
  181.      * Called when a segment write finishes.
  182.      */
  183.  
  184.     ReturnStatus (*detach) _ARGS_((struct Lfs *lfsPtr)); 
  185.     /*
  186.      * Detach an LFS file system routine. 
  187.      */
  188.     int    clientDataPerSegSize; /* Size in bytes of client data for each segment
  189.                    * for this module. */
  190. } LfsSegIoInterface;
  191.  
  192.  
  193. /*
  194.  * Layout flags.
  195.  */
  196.  
  197. #define    LFS_CLEANING_LAYOUT    0x1000
  198. #define    LFS_CHECKPOINT_LAYOUT    0x2000
  199.  
  200. extern LfsSegIoInterface *lfsSegIoInterfacePtrs[];
  201.  
  202. /*
  203.  * Macros for uses in SegIoInterface callback procedures. 
  204.  *
  205.  * See documentation in the procedure header for the slow version.
  206.  */
  207. /*
  208.  * Increase the size of the summary region to bytesNeeded bytes.
  209.  * char *
  210.  * LfsSegGrowSummary(segPtr, blocks,  bytesNeeded)
  211.  *    LfsSeg    *segPtr;     -- Segment of interest. 
  212.  *    int    blocks;        -- Insure this many data blocks remain.
  213.  *    int    bytesNeeded;    -- Number of bytes needed in the summary
  214.  *                   region.
  215.  */
  216. #define    LfsSegGrowSummary(segPtr, blocks, bytesNeeded) \
  217.     LfsSegSlowGrowSummary((segPtr), (blocks), (bytesNeeded), FALSE)
  218.  
  219. /*
  220.  * Return the value of the current pointer into the summary region.
  221.  * char *
  222.  * LfsSegGetSummaryPtr(segPtr)
  223.  *    LfsSeg    *segPtr;     -- Segment of interest. 
  224.  */
  225. #define    LfsSegGetSummaryPtr(segPtr)  ((segPtr)->curSummaryPtr)
  226.  
  227. /*
  228.  * Set the value of the current end of summary region.
  229.  * char *
  230.  * LfsSegSegSummaryPtr(segPtr, newEndPtr)
  231.  *    LfsSeg    *segPtr;     -- Segment of interest. 
  232.  *    char    *newEndPtr;    -- New value
  233.  */
  234. #define    LfsSegSetSummaryPtr(segPtr, newEndPtr)  \
  235.     ((segPtr)->curSummaryPtr = (newEndPtr))
  236.  
  237. /*
  238.  * Return the number of summary bytes left in the summary segment.
  239.  * int
  240.  * LfsSegSummaryBytesLeft(segPtr)
  241.  *    LfsSeg    *segPtr;     -- Segment of interest. 
  242.  */
  243.  
  244. #define    LfsSegSummaryBytesLeft(segPtr) \
  245.     ((segPtr)->curSummaryLimitPtr - (segPtr)->curSummaryPtr)
  246.  
  247. /*
  248.  * Return the number of file system blocks left in the segment.
  249.  * int
  250.  * LfsSegBlocksLeft(segPtr)
  251.  *    LfsSeg    *segPtr;     -- Segment of interest. 
  252.  */
  253. #define    LfsSegBlocksLeft(segPtr) ((segPtr)->curDataBlockLimit - \
  254.                   (segPtr)->curBlockOffset)
  255.  
  256. /*
  257.  * Return the disk address of an LfsSegElement
  258.  * int
  259.  * LfsSegDiskAddress(segPtr, segElementPtr)
  260.  *    LfsSeg    *segPtr;     -- Segment of interest. 
  261.  *    LfsSegElement *segElementPtr; -- Segment element of interest
  262.  */
  263.  
  264. #define    LfsSegDiskAddress(segPtr, segElementPtr) \
  265.         LfsSegSlowDiskAddress((segPtr), (segElementPtr))
  266. /*
  267.  * Add a LfsSegElement to a segment.
  268.  * LfsSegElement
  269.  * LfsSegAddDataBuffer(segPtr, blocks, bufferPtr, clientData)
  270.  *    LfsSeg    *segPtr;     -- Segment of interest. 
  271.  *    int    blocks;        -- Size of buffer to add in fsBlocks.
  272.  *    char   *bufferPtr;    -- Buffer to add.
  273.  *    ClientData clientData;    -- ClientData associated with this field.
  274.  */
  275.  
  276. #define    LfsSegAddDataBuffer(segPtr, blocks, bufferPtr, clientData) \
  277.     LfsSegSlowAddDataBuffer((segPtr), (blocks), (bufferPtr), (clientData))
  278.  
  279. #define    LfsSegGetBufferPtr(segPtr) \
  280.             ((segPtr)->segElementPtr + (segPtr)->curElement)
  281. #define    LfsSegSetBufferPtr(segPtr, bufferPtr) \
  282.         ((segPtr)->curElement = ((bufferPtr) - (segPtr)->segElementPtr))
  283.  
  284. #define    LfsSegSetCurBlockOffset(segPtr, blockOffset) \
  285.             ((segPtr)->curBlockOffset = blockOffset)
  286.  
  287. #define    LfsSegFetchBytes(segPtr, blockOffset, size) \
  288.     ((segPtr)->memPtr + LfsSegSize((segPtr)->lfsPtr) - \
  289.         LfsBlocksToBytes((segPtr)->lfsPtr, blockOffset))
  290. /* procedures */
  291.  
  292. extern void LfsSegIoRegister _ARGS_((int moduleType, 
  293.                 LfsSegIoInterface *ioInterfacePtr));
  294.  
  295. extern char *LfsSegSlowGrowSummary _ARGS_((LfsSeg *segPtr, 
  296.             int dataBlocksNeeded, int sumBytesNeeded, 
  297.             Boolean addNewBlock));
  298. extern LfsDiskAddr LfsSegSlowDiskAddress _ARGS_((LfsSeg *segPtr, 
  299.             LfsSegElement *segElementPtr));
  300. extern LfsSegElement *LfsSegSlowAddDataBuffer _ARGS_((LfsSeg *segPtr,
  301.             int blocks, char *bufferPtr, ClientData clientData));
  302.  
  303.  
  304. extern ReturnStatus LfsSegAttach _ARGS_((struct Lfs *lfsPtr,
  305.             char *checkPointPtr, int checkPointSize));
  306. extern ReturnStatus LfsSegCheckPoint _ARGS_((struct Lfs *lfsPtr, 
  307.             int flags, char *checkPointPtr, 
  308.             int *checkPointSizePtr));
  309. extern void LfsSegCheckPointDone _ARGS_((struct Lfs *lfsPtr, 
  310.             int flags));
  311. extern ReturnStatus LfsSegDetach _ARGS_((struct Lfs *lfsPtr));
  312.  
  313. #endif /* _LFSSEG */
  314.  
  315.